﻿// Decompiled with JetBrains decompiler
// Type: Template.ReferanceTemplate
// Assembly: Template, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: A1AE1EF6-30A0-49FB-9D2D-B42DD776AA13
// Assembly location: C:\Users\KasimGulcan\Desktop\Kosgeb\DynaCAD\Project\DynaCAD\bin\Debug\Template.dll

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Controls;
using System.Windows.Markup;
using XO1;

namespace Template
{
    [Serializable]
    public class ReferanceTemplate
    {
        public string PreparedBy;
        public string Name;
        
        [NonSerialized]
        public Canvas ModelOn;
        
        [NonSerialized]
        public Canvas ModelArka;
        
        public List<Type> PartTypeList;

        public ReferanceTemplate()
        {
            this.ModelOn = new Canvas();
            this.ModelArka = new Canvas();
            this.PartTypeList = new List<Type>();
        }

        public void UpdateTemplate()
        {
            foreach (Type type in this.PartTypeList)
                type.UpdateType();
        }

        public void DriveTemplate()
        {
            foreach (Type type in this.PartTypeList)
                type.DriveType();
        }

        public void aSaveTemplate()
        {

            string path = Directory.GetCurrentDirectory() + "\\Templates\\" + this.Name + ".tmp";
            if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\Templates\\"))
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\Templates\\");

            FileStream fileStream1 = new FileStream(path, FileMode.Create);
            new BinaryFormatter().Serialize((Stream)fileStream1, (object)this);
            fileStream1.Close();

            

            File.WriteAllText(Directory.GetCurrentDirectory() + "\\Templates\\" + this.Name + "_On.xaml", string.Empty);
            FileStream fileStream2 = new FileStream(Directory.GetCurrentDirectory() + "\\Templates\\" + this.Name + "_On.xaml", FileMode.OpenOrCreate);
            XamlWriter.Save((object)this.ModelOn, (Stream)fileStream2);
            fileStream2.Close();
            
            
            File.WriteAllText(Directory.GetCurrentDirectory() + "\\Templates\\" + this.Name + "_Arka.xaml", string.Empty);
            FileStream fileStream3 = new FileStream(Directory.GetCurrentDirectory() + "\\Templates\\" + this.Name + "_Arka.xaml", FileMode.OpenOrCreate);
            XamlWriter.Save((object)this.ModelArka, (Stream)fileStream3);
            fileStream3.Close();
        }
    }
}
